/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package experiments;

import java.awt.Graphics;
import java.awt.PrintJob;
import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.Pageable;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;

/**
 *
 * @author Asko
 */
public class TestPrinter implements Printable {

    @Override
    public int print(Graphics g, PageFormat pageFormat, int pageNumber)  
         throws PrinterException {
		if(pageNumber>10){
			return(Printable.NO_SUCH_PAGE);
		}else{
			g.drawString("Page "+(pageNumber+1),150,150);
		}
		return(Printable.PAGE_EXISTS);
    }
    
    public static void main(String[] args) {
        PrinterJob pj = PrinterJob.getPrinterJob();
        PageFormat pf = pj.defaultPage();
        
        pj.printDialog();
        Book b = new Book();
        b.append(new TestPrinter(), pf);
        pj.setPageable(b);
	try{
		pj.print();
		Thread.sleep(1000);
	}catch(Exception e){
		System.err.println(e.getMessage());
	}
    }
}
